package cn.cheln.support.ui.adapter;

import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import cn.cheln.explorer.ui.ViewUtil;
import cn.cheln.support.log.Logs;
import cn.cheln.support.unknown.ComparatorRepo;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class MapAdapter extends BaseAdapter
{
  public Map<Integer, Boolean> checkBoxVisibleOptions = new HashMap();
  public String checkboxname;
  public Class clazz;
  Map<Class, List<String>> clazz_fieldnames = new HashMap();
  protected Context context;
  protected List<String> fieldnames;
  Set<Field> fieldsTmp = new HashSet();
  private ActionListener[] handlers;
  protected boolean isCreatedView;
  public boolean isVisible = true;
  boolean ischecked;
  private ItemDataSrc itemDataSrc;
  private int itemLayout;
  Class lastClass;
  public int latestPosition;
  private Map<Integer, ListenerBox> listenerMaps;
  public Map<String, Integer> name_viewid = new TreeMap(ComparatorRepo.stringKey);
  public List<Integer> selected = new ArrayList();
  public int selectedNum;
  public List<Integer> selectedbck;
  public boolean startChildViewsCount = true;
  Set<Field> tmpSet = new HashSet();
  public int viewChildCount = 0;
  private Map<View, Integer> viewContentMap = new HashMap();
  public List<Integer> viewInitIndices = new ArrayList();
  protected int[] viewsid;

  public MapAdapter(Context paramContext)
  {
    this.context = paramContext;
  }

  public MapAdapter(Context paramContext, AdaptInfo paramAdaptInfo)
  {
    changeAdaptInfo(paramAdaptInfo);
    this.context = paramContext;
  }

  private void addListener(Integer paramInteger, ListenerBox paramListenerBox)
  {
    if (this.listenerMaps == null)
      this.listenerMaps = new HashMap();
    this.listenerMaps.put(paramInteger, paramListenerBox);
  }

  private void deployListeners(ActionListener[] paramArrayOfActionListener)
  {
    int i;
    int j;
    if (this.listenerMaps == null)
      this.listenerMaps = new HashMap();
    if ((paramArrayOfActionListener == null) || (paramArrayOfActionListener.length == 0));
    do
    {
      return;
      i = paramArrayOfActionListener.length;
      label33: j = 0;
    }
    while (j >= i);
    ActionListener localActionListener = paramArrayOfActionListener[j];
    if (!(this.listenerMaps.containsKey(Integer.valueOf(localActionListener.getResrcId()))))
      this.listenerMaps.put(Integer.valueOf(localActionListener.getResrcId()), new ListenerBox(this, localActionListener));
    while (true)
    {
      ++j;
      break label33:
      ((ListenerBox)this.listenerMaps.get(Integer.valueOf(localActionListener.getResrcId()))).addActionListener(localActionListener);
    }
  }

  private void fill(List<Integer> paramList, int paramInt)
  {
    paramList.removeAll(paramList);
    for (int i = 0; ; ++i)
    {
      if (i >= paramInt)
        return;
      paramList.add(Integer.valueOf(i));
    }
  }

  private void visibleALlCheckBox()
  {
    if (this.itemDataSrc == null)
      return;
    markVisible(true);
  }

  public void addItemDataSrcList(List<? extends Object> paramList)
  {
    if ((getItemDataSrc() == null) || (getItemDataSrc().getContent() == null))
      setItemDataSrc(new ItemDataSrc(paramList));
    while (true)
    {
      visibleALlCheckBox();
      return;
      ((List)getItemDataSrc().getContent()).addAll(paramList);
    }
  }

  public void addSelected(int paramInt, boolean paramBoolean)
  {
    int i;
    if (paramBoolean)
      this.selected.add(Integer.valueOf(paramInt));
    do
    {
      return;
      i = this.selected.lastIndexOf(Integer.valueOf(paramInt));
    }
    while (i < 0);
    this.selected.remove(i);
  }

  public void changeAdaptInfo(AdaptInfo paramAdaptInfo)
  {
    this.fieldnames = Arrays.asList(paramAdaptInfo.objectFields);
    this.viewsid = paramAdaptInfo.viewIds;
    this.itemLayout = paramAdaptInfo.listviewItemLayoutId;
    this.itemDataSrc = paramAdaptInfo.listviewItemData;
    this.handlers = paramAdaptInfo.actionListeners;
    deployListeners(this.handlers);
  }

  public void clearDataSrc()
  {
    if (getItemDataSrc() == null)
      return;
    getItemDataSrc().clear();
  }

  public void clearSelectOption()
  {
  }

  protected View createItemView()
  {
    return LayoutInflater.from(this.context).inflate(this.itemLayout, null);
  }

  protected void findAndBindView(View paramView, int paramInt, Object paramObject1, String paramString, Object paramObject2)
  {
    View localView;
    while (true)
    {
      try
      {
        if (!(this.name_viewid.containsKey(paramString)))
          this.name_viewid.put(paramString, Integer.valueOf(this.viewsid[this.fieldnames.indexOf(paramString)]));
        localView = paramView.findViewById(((Integer)this.name_viewid.get(paramString)).intValue());
        localView.setVisibility(0);
        if (localView instanceof CheckBox)
        {
          ((CheckBox)localView).setChecked(this.selected.contains(Integer.valueOf(paramInt)));
          ((CheckBox)localView).setVisibility(getVisibleOption(this.isVisible));
          return;
        }
        if (!(localView instanceof TextView))
          break label176;
        TextView localTextView = (TextView)localView;
        if (paramObject2 instanceof SpannableStringBuilder)
        {
          localObject = (SpannableStringBuilder)paramObject2;
          localTextView.setText((CharSequence)localObject);
          return;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        return;
      }
      Object localObject = paramObject2.toString();
    }
    if ((!(localView instanceof ImageView)) || (paramObject2 == null) || (paramObject2.toString().equals("-1")))
      label176: return;
    if (paramObject2 instanceof Integer)
      ((ImageView)localView).setImageResource(Integer.parseInt(paramObject2.toString()));
    while (localView.getVisibility() != 0)
    {
      localView.setVisibility(0);
      return;
      if (paramObject2.getClass() == BitmapDrawable.class)
        ((ImageView)localView).setImageDrawable((BitmapDrawable)paramObject2);
      if (!(paramObject2 instanceof Drawable))
        continue;
      ((ImageView)localView).setImageDrawable((Drawable)paramObject2);
    }
  }

  public int getCount()
  {
    Logs.i("== itemdatasrc " + this.itemDataSrc.getCount());
    if (this.itemDataSrc == null)
      return 0;
    return this.itemDataSrc.getCount();
  }

  public Object getItem(int paramInt)
  {
    if ((this.itemDataSrc == null) || (this.itemDataSrc.getCount() < paramInt))
      return null;
    return this.itemDataSrc.getItem(paramInt);
  }

  public ItemDataSrc getItemDataSrc()
  {
    return this.itemDataSrc;
  }

  public long getItemId(int paramInt)
  {
    return 0L;
  }

  public List<Integer> getSelected()
  {
    return this.selected;
  }

  public int getTotalSelection()
  {
    return this.selected.size();
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
    Iterator localIterator1;
    this.latestPosition = paramInt;
    Object localObject = getItem(paramInt);
    setCreatedView(false);
    if (paramView == null)
    {
      setCreatedView(true);
      paramView = createItemView();
    }
    this.viewContentMap.put(paramView, Integer.valueOf(paramInt));
    if (this.listenerMaps != null)
    {
      localIterator1 = this.listenerMaps.entrySet().iterator();
      if (localIterator1.hasNext())
        break label89;
    }
    getViewInDetail(localObject, paramInt, paramView);
    return paramView;
    label89: Map.Entry localEntry = (Map.Entry)localIterator1.next();
    Integer localInteger = (Integer)localEntry.getKey();
    ListenerBox localListenerBox = (ListenerBox)localEntry.getValue();
    View localView = ViewUtil.findViewById(paramView, localInteger.intValue());
    Iterator localIterator2 = localListenerBox.handlers.entrySet().iterator();
    while (true)
    {
      if (localIterator2.hasNext());
      switch (((Integer)((Map.Entry)localIterator2.next()).getKey()).intValue())
      {
      default:
        break;
      case 0:
        localView.setOnClickListener(localListenerBox);
        break;
      case 1:
        localView.setOnLongClickListener(localListenerBox);
        break;
      case 2:
        localView.setOnTouchListener(localListenerBox);
        break;
      case 3:
      }
      if (!(localView instanceof CheckBox))
        continue;
      ((CheckBox)localView).setOnCheckedChangeListener(localListenerBox);
    }
  }

  public Map<View, Integer> getViewContentMap()
  {
    return this.viewContentMap;
  }

  protected void getViewInDetail(Object paramObject, int paramInt, View paramView)
  {
    if (paramObject == null)
      return;
    if (paramObject instanceof Cursor)
    {
      treatCursor(paramObject, paramView, paramInt);
      return;
    }
    if (paramObject instanceof Map)
    {
      treatMap(paramObject, paramView, paramInt);
      return;
    }
    treatObject(paramObject, paramView, paramInt);
  }

  public int getVisibleOption(boolean paramBoolean)
  {
    if (paramBoolean)
      return 0;
    return 8;
  }

  public boolean hasSelected()
  {
    return (this.selected.size() > 0);
  }

  public boolean isCreatedView()
  {
    return this.isCreatedView;
  }

  public boolean isSelectAll()
  {
    return (this.selected.size() == getCount());
  }

  public Boolean isSelected()
  {
    if (this.selected.isEmpty());
    for (boolean bool = false; ; bool = true)
      return Boolean.valueOf(bool);
  }

  public void markVisible(boolean paramBoolean)
  {
    this.isVisible = paramBoolean;
  }

  public void notifyDataSetChanged()
  {
    super.notifyDataSetChanged();
  }

  public void reinitSelectedAllBck(int paramInt)
  {
    this.selected = new ArrayList(paramInt);
    this.selectedbck = new ArrayList(paramInt);
    fill(this.selectedbck, paramInt);
    this.viewContentMap.clear();
    this.name_viewid.clear();
    this.clazz_fieldnames.clear();
    this.fieldsTmp.clear();
    this.tmpSet.clear();
  }

  public void selectAll(boolean paramBoolean)
  {
    if (paramBoolean)
      if (this.selectedbck != null)
        this.selected = new ArrayList(this.selectedbck);
    do
      return;
    while (this.selected == null);
    this.selected.clear();
  }

  public void setCheckBoxName(String paramString)
  {
    if (this.fieldnames.indexOf(paramString) == -1)
      throw new IllegalStateException("");
    this.checkboxname = paramString;
  }

  public void setCreatedView(boolean paramBoolean)
  {
    this.isCreatedView = paramBoolean;
  }

  public void setItemDataSrc(ItemDataSrc paramItemDataSrc)
  {
    this.itemDataSrc = paramItemDataSrc;
    visibleALlCheckBox();
  }

  public void setSelected(List<Integer> paramList)
  {
    this.selected = paramList;
  }

  public void setStartChildViewsCount(boolean paramBoolean)
  {
    this.startChildViewsCount = paramBoolean;
    this.viewChildCount = 0;
  }

  public void treatCursor(Object paramObject, View paramView, int paramInt)
  {
    Object localObject;
    Cursor localCursor = (Cursor)paramObject;
    if (localCursor.getColumnCount() > 0)
    {
      localObject = null;
      if (localCursor.moveToNext())
        break label30;
    }
    return;
    for (int i = 0; ; ++i)
    {
      label30: if (i < localCursor.getColumnCount());
      String str1 = localCursor.getColumnName(i);
      Class localClass = (Class)this.itemDataSrc.getNameTypePair().get(str1);
      if (localClass == Integer.class);
      try
      {
        localObject = Integer.valueOf(localCursor.getInt(i));
        break label199:
        if (localClass == Long.class)
        {
          localObject = Long.valueOf(localCursor.getLong(i));
          break label199:
        }
        if (localClass == Double.class)
        {
          localObject = Double.valueOf(localCursor.getDouble(i));
          break label199:
        }
        if (localClass == String.class)
        {
          String str2 = localCursor.getString(i);
          localObject = str2;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
      while (localObject != null)
      {
        findAndBindView(paramView, paramInt, paramObject, str1, localObject);
        label199: break;
      }
    }
  }

  public void treatMap(Object paramObject, View paramView, int paramInt)
  {
    Map localMap = (Map)paramObject;
    for (int i = 0; ; ++i)
    {
      if (i >= this.fieldnames.size())
        return;
      String str = (String)this.fieldnames.get(i);
      if (!(localMap.containsKey(str)))
        continue;
      findAndBindView(paramView, paramInt, paramObject, str, localMap.get(str));
    }
  }

  public void treatObject(Object paramObject, View paramView, int paramInt)
    throws SecurityException
  {
    label115: Iterator localIterator;
    Object localObject1;
    this.lastClass = this.clazz;
    this.clazz = paramObject.getClass();
    new Field[0];
    this.tmpSet.clear();
    if ((!(this.clazz_fieldnames.containsKey(this.clazz))) || (this.clazz != this.lastClass))
    {
      this.clazz_fieldnames.put(this.clazz, this.fieldnames);
      Field[] arrayOfField = this.clazz.getFields();
      this.tmpSet.addAll(Arrays.asList(arrayOfField));
      if (this.lastClass != null)
        this.fieldsTmp.clear();
      localIterator = this.tmpSet.iterator();
      localObject1 = null;
    }
    while (true)
    {
      Field localField;
      String str;
      if (!(localIterator.hasNext()));
      do
      {
        return;
        this.tmpSet.addAll(this.fieldsTmp);
        this.fieldsTmp.clear();
        break label115:
        localField = (Field)localIterator.next();
      }
      while (this.fieldsTmp.size() == this.fieldnames.size());
      boolean bool = localField.isAccessible();
      localField.setAccessible(true);
      if (this.fieldnames.contains(localField.getName()))
        str = localField.getName();
      try
      {
        Object localObject2 = localField.get(paramObject);
        localObject1 = localObject2;
        if (localObject1 != null)
          label248: findAndBindView(paramView, paramInt, paramObject, str, localObject1);
        this.fieldsTmp.add(localField);
        localField.setAccessible(bool);
      }
      catch (IllegalArgumentException localIllegalArgumentException)
      {
        localIllegalArgumentException.printStackTrace();
        break label248:
      }
      catch (IllegalAccessException localIllegalAccessException)
      {
        localIllegalAccessException.printStackTrace();
        break label248:
      }
    }
  }

  public static abstract class ActionListener
  {
    public static final int OnCheckChanged = 3;
    public static final int OnClick = 0;
    public static final int OnLongClick = 1;
    public static final int OnTouch = 2;
    private MapAdapter baseAdapter;
    public View itemView;
    private ListenerBox listener;
    public int listenerType = -1;
    public int resrcId;

    public ActionListener(int paramInt1, int paramInt2)
    {
      this.listenerType = paramInt2;
      this.resrcId = paramInt1;
    }

    public int findViewIndex(View paramView)
    {
      View localView = (View)paramView.getParent();
      if (localView.getTag() == null)
        return findViewIndex(localView);
      return ((Integer)localView.getTag()).intValue();
    }

    public MapAdapter getBaseAdapter()
    {
      return this.baseAdapter;
    }

    public int getListenerType()
    {
      return this.listenerType;
    }

    public int getResrcId()
    {
      return this.resrcId;
    }

    public abstract void handle(View paramView, ListenerBox paramListenerBox);

    public void invokeHandle(View paramView, ListenerBox paramListenerBox)
    {
      this.listener = paramListenerBox;
      handle(paramView, paramListenerBox);
    }

    public void setBaseAdapter(MapAdapter paramMapAdapter)
    {
      this.baseAdapter = paramMapAdapter;
    }

    public void setLWBaseAdapter(MapAdapter paramMapAdapter)
    {
      setBaseAdapter(paramMapAdapter);
    }
  }

  public static class AdaptInfo
  {
    public MapAdapter.ActionListener[] actionListeners;
    public ItemDataSrc listviewItemData;
    public int listviewItemLayoutId;
    public String[] objectFields;
    public int[] viewIds;
  }

  private class ViewHolder
  {
    View[] viewCaches;
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.support.ui.adapter.MapAdapter
 * JD-Core Version:    0.5.2
 */